home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8699 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.4 KB  |  73 lines

  1. Path: news.cstone.net!usenet
  2. From: scottv@cstone.net (Scott)
  3. Newsgroups: comp.lang.c++
  4. Subject: Subclassing a Window - Getting a Pointer to a WNDPROC Class Method? Valid?
  5. Date: 26 Feb 1996 02:50:03 GMT
  6. Organization: Cornerstone Networks - Pure Internet!
  7. Message-ID: <4gr74r$fj8@dot.cstone.net>
  8. NNTP-Posting-Host: dialin11.cstone.net
  9. Mime-Version: 1.0
  10. Content-Type: Text/Plain; charset=US-ASCII
  11. X-Newsreader: WinVN 0.99.7
  12.  
  13. I'm writing a class definition that will need to subclass a window inorder to 
  14. monitor for such messages as Size, Destroy and others.  Is it valid C++ 
  15. syntax to attempt to get the pointer to a method that is a WNDPROC routine?  
  16. If so, how do I obtain it (I get an invalid cast from long to class member 
  17. pointer).  If this is not ligitimate C++ syntax, how can I attach an instance 
  18. of the class to the subclass WNDPROC.  Here is an example to make it clearer.
  19.  
  20. class CThing
  21. {
  22. public:
  23.     long m_pOriginalWndProc;
  24.     HWND m_hWnd;
  25. public:
  26.     void SubclassWindow();
  27.     void UnSubclassWindow();
  28.     LRESULT WNDPROC SubclassWndProc(....);
  29. };
  30.  
  31. void CThing::SubclassWindow()
  32. {
  33.     m_pOriginalWndProc=SetWindowLong(m_hWnd,GWL_WNDPROC,???????);
  34. };
  35.  
  36. void CThing::UnSubclassWindow()
  37. {
  38.     SetWindowLong(m_hWnd,GWL_WNDPROC,m_pOriginalWndProc);
  39. };
  40.  
  41. LRESULT WNDPROC CThing::SubclasWndProc(....)
  42. {
  43.     switch (Message)
  44.     {
  45.     case WM_SIZE:
  46.         break;
  47.     }
  48.     CallWndProc(m_pOriginalWndProc,....);
  49. };
  50.  
  51.     The m_hWnd is a handle to a window that I need to monitor for these 
  52. events.  I can use a normal (not a method of the class) routine to subclass 
  53. the window, but I need to attach the class object to the subclassing routine 
  54. inorder to trigger events within the object - the class will have many 
  55. instances at any given time.  If I can't use the pointer to the method, what 
  56. would be a clean method of communicating the pointer to the class object to 
  57. the subclassing routine?  If anyone could possibly help, I would appreciate 
  58. it - please email me (I don't get into the news groups enough) directly.  
  59. Thanks in advance...this should be a simple question of whether the C++ 
  60. syntax is valid - but I can't find documentation online with VC++ 4.0.
  61.  
  62.             Sincerely,
  63.             N. Scott Vann    
  64.             Motivational Concepts, Inc.
  65.             Software Engineer/Multimedia Training Systems
  66.  
  67. P.S. - In a nut shell, with C++, can you obtain a pointer to an objects 
  68. method routine?  This is to be used for subclassing a window ... if so, what 
  69. is the proper syntax?
  70.  
  71. Thanks again...
  72.  
  73.